*Set up ;
%let folder=/n/home12/dbarnhart/betterbirth_paper3/analysis_02_13_2019;
%let dtdt=0213;
%let today=0328;
libname bb "&folder./cleaning";
libname raw "&folder./raw_data";
libname analysis "&folder";
libname datavrs "&folder./dataverse";
%include "&folder./cleaning/formats_betterbirth.sas";
filename macros "&folder./macros";
options mautosource sasautos=(macros);
options helpbrowser=sas;
option SPOOL; 
ods escapechar='~'; 


data datavrs.health_intervention;
	set analysis.rct_&dtdt 
	(keep= coaching_updt bacov_tot coach_mo bacov_mo coach_wk bacov_wk
	bacoach_mean bacoach_mean_mo  bacoach_mean_wk
	bacoach_sd bacoach_sd_mo bacoach_sd_wk
	distance_to_district_hosp_km staff_nurse_and_anm_matching 
	delivery_load_matching hpd hub_name observed_bycoach mos_since_mtch
	prim_composite sec_composite site_id arm_name admission_date);
	where arm_name="intervention";
	
	label
	 arm_name="Randomization arm"
	 coaching_updt="Total coaching accrued"
	 bacoach_sd="Standard deviation of coaching visits among BAs" 
	 delivery_load_matching="Delivery load of facility at matching"
	 distance_to_district_hosp_km="Distance to district hospital (km)"
	 hub_name="Geographic research hub"
	 observed_bycoach="Whether birth occurred on date of coaching visit"
	  prim_composite="Primary composite: Maternal Morbidity, Infant & Maternal
	 Mortality"
	 sec_composite="Secondary composite: Infant & Maternal Mortality" 
	 site_id="Site ID"
	 staff_nurse_and_anm_matching="Birth attendant staff at matching"
	 ;
	 
	run;


data datavrs.ebp_intervention;
	set analysis.fada_&dtdt 
	(keep=coaching_updt bacov_tot coach_mo bacov_mo coach_wk bacov_wk
	bacoach_mean bacoach_mean_mo  bacoach_mean_wk
	bacoach_sd bacoach_sd_mo bacoach_sd_wk
	distance_to_district_hosp_km staff_nurse_and_anm_matching 
	delivery_load_matching hpd hub_name observed_bycoach mos_since_mtch
	ebp_full site_id arm_name admission_date);
	where arm_name="intervention";
	
	 label
	 arm_name="Randomization arm"
	 bacoach_sd="Standard deviation of coaching visits among BAs" 
	 delivery_load_matching="Delivery load of facility at matching"
	 distance_to_district_hosp_km="Distance to disctrict hospital"
	 ebp_full="Number of EBPs that were successfully completed (out of 18)"
	 hub_name="Geographic research hub"
	 observed_bycoach="Whether birth occurred on date of coaching visit"
	 prim_composite="Primary composite: Maternal Morbidity, Infant & Maternal
	 Mortality"
	 sec_composite="Secondary composite: Infant & Maternal Mortality" 
	 site_id="Site ID"
	 staff_nurse_and_anm_matching="Birth attendant staff at matching"
	 ;
	run;

	
data datavrs.all_ba_visits;
	length ba_code $10;
	set raw.all_ba_visits (keep=ba_code otis_observation_date site_id);
	
	format ba_code $10.;
	label site_id="Site ID"
		  ba_code="Birth attendant ID";
	run;
	

ods excel file="&folder./dataverse/codebook_ebp_health_inteverntion_all_ba_visits.xlsx"
	options(sheet_interval="proc" sheet_name="Health outcome data");
proc contents data=	datavrs.health_intervention;
	run;
	
ods excel options(sheet_interval="proc" sheet_name="EBP adherence data");	
proc contents data=datavrs.ebp_intervention;
	run;	

ods excel options(sheet_interval="proc" sheet_name="Coaching visit dates");	
proc contents data=datavrs.all_ba_visits;
	run;		
	
	
